<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/swiper.css">
    <script src="js/vue.js"></script>
    <script src="js/swiper.js"></script>
    <style>
        .box {
            width: 800px;
            height: 300px;
            background-color: yellow;
            margin: auto;
        }
    </style>
</head>

<body>
    <div id="box">
        <swiper :key="dataList.length" :myconfig="{loop:true}">
            <template #slide>
                <div class="swiper-slide" v-for="item in dataList">{{item}}</div>
            </template>
            <template #arrows>
                <div class="swiper-button-next"></div>
                <div class="swiper-button-prev"></div>
            </template>
            <template #pagination>
                <div class="swiper-pagination"></div>
            </template>
        </swiper>
    </div>

    <script>
        Vue.component("swiper", {
            props: ["myconfig"],
            template: `
                <div class="swiper-container box">
                    <div class="swiper-wrapper">
                        <slot name="slide"></slot>
                    </div>
                    <slot name="arrows"></slot>
                    <slot name="pagination"></slot>
                </div>
            `,
            mounted() {
                //console.log(this.myconfig)
                var config = {
                    loop: false,
                    navigation: {
                        nextEl: '.swiper-button-next',
                        prevEl: '.swiper-button-prev'
                    },
                    pagination: {
                        el: '.swiper-pagination',
                    },
                }
                new Swiper(".box", Object.assign(config, this.myconfig))
            }
        })
        new Vue({
            el: "#box",
            data: {
                dataList: []
            },
            created() { //初始化动态加载数据
                var _this = this;
                setTimeout(function() {
                    _this.dataList = ["首页", "商品", "详情", "购物车", "用户中心"];
                }, 2000)
            }
        })
    </script>
</body>

</html>